require(["mmRouter"],function () {
	var model = avalon.define("mean", function(vm) {
		vm.currentTag = 'home'
		vm.currentPage = "home.html";
		vm.loadingVisible = false;//加载提示是否显示
		
		vm.isLoadPageOver = false;//是否加载完成

		//手机上消失menu的方法
		vm.dismissMenu = function(){
			if(window.innerWidth <768){
				$(".navbar-toggle").click();
			}
		}
		
		//加載page完成的回調
		vm.loadPageOver = function() {
			vm.$fire("all!init", vm.currentPage);
			scroll(0,0);
			vm.loadingVisible = false;
			vm.isLoadPageOver = true;
		};
	});
	
	//resize监听
	window.onresize = function(){
		model.$fire("all!resize");
	}
	
	//指定路由
	function routeCallBack() {
		setTimeout(function(){
			model.loadingVisible = !model.isLoadPageOver;
		},1000);
		model.isLoadPageOver = false;
		var params = this.params;
		var path = this.path;
		
		if(path == "/"){
			path = '/home';
		}
		
		model.currentTag = path.split('/')[1];
		
		var currentPage = model.currentTag + ".html";
		//案例详情路由
	    if ("caseId" in params && model.currentTag == 'case') {
	    	if(params.caseId.indexOf(".html")>=0){
	    		currentPage = 'case/'+params.caseId;
	    	}else{
	    		currentPage = 'case/'+params.caseId + '.html';
	    	}
	    }
	    //产品展示路由
	    else if("showId" in params && model.currentTag == 'show'){
	    	if(params.showId.indexOf(".html")>=0){
	    		currentPage = 'show/'+params.showId;
	    	}else{
	    		currentPage = 'show/'+params.showId + '.html';
	    	}
	    }
	    //新闻路由
	    else if("newsId" in params && model.currentTag == 'home'){
	    	if(params.newsId.indexOf(".html")>=0){
	    		currentPage = 'home/'+params.newsId;
	    	}else{
	    		currentPage = 'home/'+params.newsId + '.html';
	    	}
	    }
	    model.currentPage = currentPage;
	}

	//五个子界面路由
	avalon.router.get("/", routeCallBack);
	avalon.router.get("/home", routeCallBack);
	avalon.router.get("/show", routeCallBack);
	avalon.router.get("/case", routeCallBack);
	avalon.router.get("/about",routeCallBack);
	avalon.router.get("/join", routeCallBack);
	
	//产品案例路由
	avalon.router.get("/show/{showId}/",routeCallBack);

	//经典案例路由
	avalon.router.get("/case/{caseId}/",routeCallBack);
	
	//新闻路由
	avalon.router.get("/home/{newsId}/",routeCallBack);

	avalon.history.start({
	    basepath: "/avalon"
	});

	//设置回到顶部
	$.scrollUp({
		animation: 'fade',
		scrollImg: { active: true, type: 'background'}
	});

	avalon.scan();
});